libtest.sh: use G_TEST_SRCDIR, G_TEST_BUILDDIR to find resources
authorSimon McVittie <smcv@debian.org>
Thu, 31 Mar 2016 17:29:44 +0000 (18:29 +0100)
committerColin Walters (automation) <walters+githubbot@verbum.org>
Thu, 31 Mar 2016 18:54:13 +0000 (18:54 +0000)
This fixes the bug that in installed-tests that run testlib.sh under
"bash -c" (i.e. the C and JS tests), $(dirname $0) is "." and we can't do
the LD_PRELOAD correctly:

ERROR: ld.so: object './libreaddir-rand.so' from LD_PRELOAD cannot be
preloaded (cannot open shared object file): ignored.

Similarly, those tests can't copy gpghome correctly.

This also removes the confusing situation that SRCDIR in libtest.sh
(which is ${top_srcdir}/tests) does not mean the same thing as SRCDIR
in test-abi.sh (which is just ${top_srcdir}).

Signed-off-by: Simon McVittie <smcv@debian.org>
Closes: #234
Approved by: cgwalters

tests/libtest.sh
tests/test-archivez.sh
tests/test-delta.sh
tests/test-pull-archive-z.sh

index 03b498aa2956dfe87b5435b331fd9daf8b60e2a0..aaa553a0493078ffd90ebb953915878e1aa22c60 100755 (executable)
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-SRCDIR=$(dirname $0)
+if [ -n "${G_TEST_SRCDIR:-}" ]; then
+  test_srcdir="${G_TEST_SRCDIR}/tests"
+else
+  test_srcdir=$(dirname $0)
+fi
+
+if [ -n "${G_TEST_BUILDDIR:-}" ]; then
+  test_builddir="${G_TEST_BUILDDIR}/tests"
+else
+  test_builddir=$(dirname $0)
+fi
 
 assert_not_reached () {
     echo $@ 1>&2; exit 1
@@ -54,7 +64,7 @@ export TEST_GPG_KEYID_3="DF444D67"
 # homedir in order to create lockfiles.  Work around
 # this by copying locally.
 echo "Copying gpghome to ${test_tmpdir}"
-cp -a ${SRCDIR}/gpghome ${test_tmpdir}
+cp -a "${test_srcdir}/gpghome" ${test_tmpdir}
 export TEST_GPG_KEYHOME=${test_tmpdir}/gpghome
 export OSTREE_GPG_HOME=${test_tmpdir}/gpghome/trusted
 
@@ -63,9 +73,9 @@ if test -n "${OT_TESTS_DEBUG:-}"; then
 fi
 
 if test -n "${OT_TESTS_VALGRIND:-}"; then
-    CMD_PREFIX="env G_SLICE=always-malloc valgrind -q --leak-check=full --num-callers=30 --suppressions=${SRCDIR}/ostree-valgrind.supp"
+    CMD_PREFIX="env G_SLICE=always-malloc valgrind -q --leak-check=full --num-callers=30 --suppressions=${test_srcdir}/ostree-valgrind.supp"
 else
-    CMD_PREFIX="env LD_PRELOAD=${SRCDIR}/libreaddir-rand.so"
+    CMD_PREFIX="env LD_PRELOAD=${test_builddir}/libreaddir-rand.so"
 fi
 
 assert_streq () {
index 999157deff442902ec5ef379b1cf31efaae43bc7..b879328474f34d4663c9e92a655a45dd29dc8b26 100755 (executable)
@@ -25,7 +25,7 @@ echo '1..11'
 
 setup_test_repository "archive-z2"
 
-. ${SRCDIR}/archive-test.sh
+. ${test_srcdir}/archive-test.sh
 
 cd ${test_tmpdir}
 mkdir repo2
index a6fd6f88bdbd9d008b8ab3543030f4cd1687bbd9..411e9b042bead4a2bd9899085bf982c5ef6a1fd3 100755 (executable)
@@ -130,9 +130,9 @@ assert_streq "${totalsize_orig}" "${totalsize_swapped}"
 
 echo 'ok generate + show endian swapped'
 
-tar xf ${SRCDIR}/pre-endian-deltas-repo-big.tar.xz
+tar xf ${test_srcdir}/pre-endian-deltas-repo-big.tar.xz
 mv pre-endian-deltas-repo{,-big}
-tar xf ${SRCDIR}/pre-endian-deltas-repo-little.tar.xz
+tar xf ${test_srcdir}/pre-endian-deltas-repo-little.tar.xz
 mv pre-endian-deltas-repo{,-little}
 legacy_origrev=$(${CMD_PREFIX} ostree --repo=pre-endian-deltas-repo-big rev-parse main^)
 legacy_newrev=$(${CMD_PREFIX} ostree --repo=pre-endian-deltas-repo-big rev-parse main)
index 2ea23871fbd121dcc4ee28ba6119df54c8cd78a2..66f8873e890210f46399b465ecedc088be72a106 100755 (executable)
@@ -23,4 +23,4 @@ set -euo pipefail
 
 setup_fake_remote_repo1 "archive-z2"
 
-. ${SRCDIR}/pull-test.sh
+. ${test_srcdir}/pull-test.sh